﻿// Learn more about F# at http://fsharp.net

module Module1

open System
open FinMkts

type OrderAction = { Quantity: double; Market: MarketListing }

type AccountReply =
    | Confirmed of Guid
    | Rejected of string
 
type AccountRequest =
    | Buy of OrderAction * AsyncReplyChannel<AccountReply>
    | Sell of OrderAction * AsyncReplyChannel<AccountReply>
    | Cancel of Guid * AsyncReplyChannel<AccountReply>

let agent = fun (inbox : MailboxProcessor<AccountRequest>) -> 
        async { 
            while true do
                 let! request = inbox.Receive() 
                 match request with
                 | Buy (order, reply) -> reply.Reply(Confirmed(Guid.NewGuid()))
                 | Sell (order, reply) -> reply.Reply(Rejected("Sell not implemented"))
                 | Cancel (orderId, reply) -> reply.Reply(Rejected("Cancel not implemented"))
        } 

let consumeThreeMessages = MailboxProcessor.Start agent
 

